PASSWORD_ACTIVE=$(sudo -u postgres psql -c "select rolpassword is not null from pg_authid where rolname='postgres'" 2>/dev/null | sed -n '3p' | awk '{$1=$1};1')
if [[ "${PASSWORD_ACTIVE}" != "t" ]]
then
	sudo -u postgres psql -c "alter user postgres with password 'postgres'" 2>/dev/null
fi

hba_file=$(sudo -u postgres psql -c "show hba_file" 2>/dev/null | sed -n '3p')
echo ${hba_file}
FIRST_ACTIVE_NUMBER=$(sudo cat -n ${hba_file} | grep -vE '[0-9]+\s+#' | grep -E '[0-9]+\s+\w+' | head -n 1 | awk '{print $1}')
sudo cat ${hba_file} | grep 'host    all    all    0.0.0.0/0    scram-sha-256'
if [[ $? -eq 1 ]]
then
	sudo sed -i  ''"${FIRST_ACTIVE_NUMBER}"'ihost    all    all    0.0.0.0/0    scram-sha-256' ${hba_file}
fi
server_name=$(sudo ls -1 /usr/lib/systemd/system | grep postgres)
simple_server_name=${server_name%%.service}
sudo systemctl restart ${simple_server_name}
